/*
 * FileStore.java
 *
 * Created on __DATE__, __TIME__
 */

package forms;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author  __USER__
 */
public class FileStore extends javax.swing.JFrame {

	private static StartForm tabbedPaneExample;

	/** Creates new form FileStore */
	public FileStore(StartForm tabbedPaneExample) {
		initComponents();
		this.tabbedPaneExample = tabbedPaneExample;
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jFileChooser1 = new javax.swing.JFileChooser();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jFileChooser1.setAcceptAllFileFilterUsed(false);
		jFileChooser1.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
		jFileChooser1.setFileFilter(new FileFilter() {
			
			@Override
			public String getDescription() {
				return "PNG-File (*.png)";
			}
			
			@Override
			public boolean accept(File f) {
		        String fName = f.getName().toUpperCase();
		        if (fName.endsWith(".PNG") || f.isDirectory()) {
		            return true;
		        } else {
		            return false;   
		        }
			}
		});
		jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jFileChooser1ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jFileChooser1,
								javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(22, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jFileChooser1,
								javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		JFileChooser chooser = (JFileChooser) evt.getSource();
		if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
			//			jFileChooser1.setVisible(false);
			tabbedPaneExample.storePanSharpenedImage(jFileChooser1
					.getSelectedFile().getAbsolutePath());
			dispose();
		} else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
			//			jFileChooser1.setVisible(false);
			dispose();
		}
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new FileStore(tabbedPaneExample).setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JFileChooser jFileChooser1;
	// End of variables declaration//GEN-END:variables

}